using System;
using System.Windows.Forms;
using Mbs.Elements;

namespace Mbs.Windows.Elements
{
	public class ToolStripElementFactory : MarshalByRefObject, IElementFactory
	{
		
		public IElement Create(object uiElement)
		{
			if (uiElement is ToolStrip)
				return new ToolStripItemCollectionElement(((ToolStrip)uiElement).Items);
            if (uiElement is ContextMenuStrip)
                return new ToolStripItemCollectionElement((uiElement as ContextMenuStrip).Items);
            if (uiElement is ToolStripSeparator)
                return new ToolStripSeparatorElement(uiElement as ToolStripSeparator);
            if (uiElement is ToolStripDropDownItem)
                return new ToolStripDropDownItemElement(uiElement as ToolStripDropDownItem);
			if (uiElement is ToolStripItem)
				return new ToolStripItemElement((ToolStripItem)uiElement);
			if (uiElement is ToolStripItemCollection)
				return new ToolStripItemCollectionElement((ToolStripItemCollection)uiElement);

			throw new ArgumentException("uiElement");
		}

		public bool Supports(object uiElement)
		{
			return (uiElement is ToolStrip) 
                || (uiElement is ContextMenuStrip)
                || (uiElement is ToolStripItem) 
                || (uiElement is ToolStripItemCollection);
		}
	}
}
